<?php
    require_once ('config/path_config.php');
    require_once(ROOTDIR."include/db_info.inc.php");
    $vcode="";
    if( isset($_POST['vcode']) ) {
        $vcode=trim($_POST['vcode']);
    }
    if($OJ_VCODE&&($vcode!= $_SESSION["vcode"]||$vcode==""||$vcode==null) ){
		echo "<script language='javascript'>\n";
		echo "alert('Verify Code Wrong!');\n";
		echo "history.go(-1);\n";
		echo "</script>";
		exit(0);
    }
    require_once("./include/login-".$OJ_LOGIN_MOD.".php");
    $user_id=$_POST['user_id'];
    $password=$_POST['password'];
    if (get_magic_quotes_gpc ()) {
        $user_id= stripslashes ( $user_id);
        $password= stripslashes ( $password);
    }

    $userName = check_login($user_id, $password);
	if ($userName != null )
    {
        // 设置用户session
        $_SESSION['user_id']=$user_id;
        $_SESSION['user_name'] = $userName;

        // 不允许使用初始密码 123456 作为密码
        if ($password ==  "e10adc3949ba59abbe56e057f20f883e" ) {
            $_SESSION['need_chg_passwd'] = true;
            // 跳转到密码修改页面，要求修改密码
            echo "<script language='javascript'>\n";
            echo "window.location.href='/modifypasswdpage.php'\n";
            echo "</script>";
        }
        else {
            // 查询用户权限
            $sql="SELECT `rightstr` FROM `privilege` WHERE `user_id`=?";
            $result=pdo_query($sql, $user_id);
            foreach ($result as $row) {
                $_SESSION[$row['rightstr']]=true;
            }
            echo "<script language='javascript'>\n";
            echo "history.go(-2);\n";
            echo "</script>";
        }
	}else {
		echo "<script language='javascript'>\n";
		echo "alert('用户名或密码错误!(请加入QQ群：567784694联系群主重置密码!）');\n";
		echo "history.go(-1);\n";
		echo "</script>";
	}
?>
